﻿#include <Windows.h>
#include <stdio.h>


void CopySelf()
{
	// 保存自身程序的路径
	char szSelfName[MAX_PATH] = { 0 };
	// 保存Windows目录的路径
	char szWindowsPath[MAX_PATH] = { 0 };
	// 保存系统目录的路径
	char szSystemPath[MAX_PATH] = { 0 };
	// 临时路径变量
	char szTmpPath[MAX_PATH] = { 0 };
	GetModuleFileName(NULL, szSelfName, MAX_PATH);//获取当前执行进程的全路径（包括进程名字）
	GetWindowsDirectory(szWindowsPath, MAX_PATH);
	GetSystemDirectory(szSystemPath, MAX_PATH);
	strcat(szWindowsPath, "\\backdoor.exe");
	strcat(szSystemPath, "\\backdoor.exe");
	CopyFile(szSelfName, szWindowsPath, FALSE);
	CopyFile(szSelfName, szSystemPath, FALSE);
	DeleteFile(szWindowsPath);
	DeleteFile(szSystemPath);
}



//获得系统的相关信息
void GetSysInfo()
{
	char szComputerName[MAXBYTE] = { 0 };
	char szUserName[MAXBYTE] = { 0 };
	unsigned long nSize = MAXBYTE;
	OSVERSIONINFO OsVer;
	OsVer.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
	//获得系统的相关信息
	GetVersionEx(&OsVer);//这里默认会报错，想要继续用这个函数就修改属性：C/C++ -> SDL检查 -> 否
	if (OsVer.dwPlatformId == VER_PLATFORM_WIN32_NT)
	{
		if (OsVer.dwMajorVersion == 5 && OsVer.dwMinorVersion == 1)
		{
			printf("Windows XP %s \r\n", OsVer.szCSDVersion);
		}
		else if (OsVer.dwMajorVersion == 5 && OsVer.dwMinorVersion == 0)
		{
			printf("Windows 2K \r\n");
		}
	}
	else
	{
		printf("Ohter System \r\n");
	}
	//获取计算机名称
	GetComputerName(szComputerName, &nSize);
	printf("Computer Name is %s \r\n", szComputerName);
	nSize = MAXBYTE;
	//获取当前用户名称
	GetUserName(szUserName, &nSize);
	printf("User Name is %s \r\n", szUserName);
}


int main()
{
	CopySelf();
	GetSysInfo();
	return 0;
}